1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package net.sf.webphotos.action;
17  
18  import java.awt.event.ActionEvent;
19  import java.io.File;
20  import javax.swing.AbstractAction;
21  import javax.swing.JComboBox;
22  import javax.swing.JFileChooser;
23  import javax.swing.JTable;
24  import net.sf.webphotos.Album;
25  import net.sf.webphotos.gui.PainelWebFotos;
26  import net.sf.webphotos.gui.util.ImageFilter;
27  import net.sf.webphotos.gui.util.TableModelFoto;
28  import net.sf.webphotos.gui.util.TableSorter;
29  import net.sf.webphotos.util.Util;
30  import org.apache.commons.configuration.Configuration;
31  
32  
33  
34  
35  
36  public class AcaoAdicionarFoto extends AbstractAction {
37  
38      private static final long serialVersionUID = 8331561928830049243L;
39      private static File diretorioInicial;
40      private JFileChooser fileChooser;
41      private JTable tbFotos;
42      private String larguraColunasFotos;
43      private String titulo;
44      private JComboBox lstCreditosTabelaFotos;
45  
46      
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57      public AcaoAdicionarFoto(JTable tabela, JComboBox combo, String tituloDialogo) {
58          Configuration c = Util.getConfig();
59          diretorioInicial = Util.getFolder("diretorioAdicionarFotos");
60          tbFotos = tabela;
61          lstCreditosTabelaFotos = combo;
62          larguraColunasFotos = c.getString("colunas2");
63          titulo = tituloDialogo;
64      }
65  
66      
67  
68  
69  
70  
71  
72  
73  
74  
75  
76      @Override
77      public void actionPerformed(ActionEvent e) {
78          fileChooser = new JFileChooser();
79          fileChooser.setAcceptAllFileFilterUsed(false);
80          fileChooser.setFileFilter(new ImageFilter());
81          fileChooser.setDialogTitle(titulo);
82          fileChooser.setApproveButtonText("Ok");
83          fileChooser.setApproveButtonToolTipText("Adiciona as fotos selecionadas ao álbum");
84          fileChooser.setMultiSelectionEnabled(true);
85  
86          if (diretorioInicial != null && diretorioInicial.isDirectory()) {
87              fileChooser.setCurrentDirectory(diretorioInicial);
88          }
89  
90          int retornoFc = fileChooser.showOpenDialog(null);
91  
92          if (retornoFc == JFileChooser.APPROVE_OPTION && fileChooser.getSelectedFiles().length > 0) {
93              Album.getAlbum().adicionarFotos(fileChooser.getSelectedFiles());
94  
95              
96  
97  
98              TableModelFoto.getModel().update();
99              TableModelFoto.getModel().fireTableDataChanged();
100             tbFotos.setModel(new TableSorter(TableModelFoto.getModel(), tbFotos.getTableHeader()));
101             tbFotos.getColumnModel().getColumn(2).setCellEditor(new javax.swing.DefaultCellEditor(lstCreditosTabelaFotos));
102 
103             
104 
105 
106             Util.ajustaLargura(tbFotos, larguraColunasFotos);
107             tbFotos.repaint();
108 
109             
110 
111 
112             PainelWebFotos.alteracaoDetectada();
113 
114             
115 
116 
117             diretorioInicial = null;
118             diretorioInicial = new File(fileChooser.getSelectedFiles()[0].getParent());
119         }
120     }
121 }